package com.zhuzhe.blog.system.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zhuzhe.blog.base.ResponseData;
import com.zhuzhe.blog.system.requestDto.SysRolePageDto;
import com.zhuzhe.blog.system.requestDto.SysUserPageDto;
import com.zhuzhe.blog.system.responseVo.SysRoleListVo;
import com.zhuzhe.blog.system.responseVo.SysUserListVo;
import com.zhuzhe.blog.system.service.ISysUserService;
import feign.Param;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 用户信息表 前端控制器
 * </p>
 *
 * @author u53
 * @since 2020-10-13
 */
@Api(value = "用户管理接口", description = "提供用户的增删改查接口")
@RestController
@RequestMapping("/sys-user")
public class SysUserController {


    @Autowired
    private ISysUserService sysUserService;


    @ApiOperation("根据条件分页查询用户列表")
    @PostMapping("/seach")
    public ResponseData<IPage<SysUserListVo>> queryPage(@RequestBody SysUserPageDto sysUserPageDto) {
        return sysUserService.queryPage(sysUserPageDto);
    }


    @ApiOperation("根据用户id查询当前用户所拥有的角色ids")
    @ApiImplicitParam(name = "id", value = "用户id", required = true)
    @GetMapping("/{id}/menu/ids")
    public ResponseData<List<String>> findRoleIdsByid(@PathVariable("id") String id) {
        return sysUserService.findRoleIdsByid(id);
    }

    @PostMapping("/{id}/user/saveUserRole")
    @ApiOperation("授权用户角色")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "用户id", required = true),
            @ApiImplicitParam(name = "roleIds", value = "角色ids", readOnly = true)
    })
    public ResponseData<Integer> saveUserRole(@PathVariable("id") String id,
                                              @RequestBody List<String> roleIds) {

        return sysUserService.saveUserRole(id, roleIds);
    }


}
